/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package racer.client.data;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 *
 * @author Lieven
 */
public class RegEx {

	public static String positie_expression = ":=:(.);fromID=(.*);X=(.*);Y=(.*);A=(.*);AT=(.*):=:";
	public static String chat_expression = ":=:(.);fromID=(.*);toID=(.*);text=(.*):=:";
	public static String settings_expression = ":=:(.);fromID=(.*);toID=(.*);settingstring=(.*):=:";
	public static String id_expression = ":=:(.*?);(.*):=:";
	public static String createrace_expression = ":=:(.);fromID=(.*);mapName=(.*);maxPlayers=(.*):=:";
	public static String joinrace_expression = ":=:(.);fromID=(.*);raceID=(.*):=:";
	public static String listracereq_expression = ":=:(.);fromID=(.*):=:";
	public static String listrace_expression = ":=:(.);fromID=(.*);raceID=(.*);mapName=(.*);numPlayers=(.*);maxPlayers=(.*);raceid=-1:=:";
	public static String login_expression = ":=:(.);playerID=(.*):=:";
	public static String gameover_expression = ":=:(.);fromID=(.*):=:";
	public static String gamestarted_expression = ":=:(.);raceID=(.*):=:";
	public static String map_expression = ":=:(.*);mapName=(.*);mapString=(.*):=:";
	
	
    //used by parser (incomingFromServer)    
    //also to load map in TiledMap etc
    
    public static boolean Matches(Matcher m,int index){
        return m.find(index);
    }
    
    public static String getExpression(int id) {
    	switch(id) {
    	case 0: return login_expression;
    	case 1: return positie_expression;
    	case 2: return chat_expression;
    	case 3: return settings_expression;
    	case 4: return createrace_expression;
    	case 5: return joinrace_expression;
    	case 6: return listracereq_expression;
    	case 7: return listrace_expression;
    	case 8: return gameover_expression;
    	case 9: return gamestarted_expression;
    	case 10: return map_expression;
    	default: return null;
    	}
    }
    
    public static Matcher getMatcher(String expressie,String msg){
    	if(expressie == null || msg == null)
    		return null;
       Pattern patroon = Pattern.compile(expressie,Pattern.CASE_INSENSITIVE);
       Matcher vergelijk = patroon.matcher(msg);
       
       return vergelijk;
        
    }        
    
    
    
    
}

